/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package com.xiashitech.agent.instrumentation.dubbo.inst.lt27;

import com.google.auto.service.AutoService;
import com.xiashitech.agent.rule.usermatch.Register;
import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.asList;

@AutoService(InstrumentationModule.class)
public class DubboLt27InstrumentationModule extends InstrumentationModule {
    public DubboLt27InstrumentationModule() {
        super("xs-netty", "xs-netty-4.1");
    }
    @Override
    public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) {
        helperResourceBuilder.registerForAllClassLoaders(
                "META-INF/services/com.alibaba.dubbo.remoting.exchange",
                "xs-classloader-resources/com.alibaba.dubbo.remoting.exchange");
    }
/*  @Override
  public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
    // Class added in 4.1.0 and not in 4.0.56 to avoid resolving this instrumentation completely
    // when using 4.0.
    return hasClassesNamed("io.netty.handler.codec.http.CombinedHttpHeaders");
  }*/

    @Override
    public List<TypeInstrumentation> typeInstrumentations() {
        return asList(
                new AbstractPeerReceivedInstrumentation(),
             new AbstractPeerSendInstrumentation()
        );
    }
  @Override
  public List<String> getAdditionalHelperClassNames() {
    List<String> helperClassNames = new ArrayList();
    helperClassNames.addAll(Arrays.asList(
//          "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
            "com.xiashitech.agent.instrumentation.dubbo.XSDubboLt27Handler"
            ));
    helperClassNames.addAll(Register.registUserMatch());
    return helperClassNames;
  }
}
